package com.da.javatest.leetCode2;

import java.util.ArrayList;
import java.util.List;

public class Code763 {
    public static void main(String[] args) {
        new Code763().partitionLabels("caedbdedda");
    }

    private List<Integer> result = new ArrayList<>();

    public List<Integer> partitionLabels(String S) {
        if (S == null) return result;
        if (S.length() != 0) {
            char[] chars = S.toCharArray();
            int end = S.lastIndexOf(chars[0]) + 1;
            if (S.length() == end) {
                result.add(end);
                return result;
            }
            for (int i = 0; i < end; i++) {
                int e = S.lastIndexOf(chars[i]) + 1;
                if (e > end) end = e;
            }
            result.add(end);
            partitionLabels(S.substring(end));
        }
        return result;
    }
}
